/**
 * 
 */
package com.gr.staffpm.notes;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.joda.time.format.DateTimeFormat;

import com.gr.staffpm.notes.activity.ActivityMessage;
import com.gr.staffpm.pages.management.feedback.TeamFeedbackPage;
import com.gr.staffpm.pages.tasks.ViewTask;
import com.gr.staffpm.utils.DateTimeUtils;


/**
 * @author Graham Rhodes 20 Feb 2011 16:33:26
 */
public class NotificationPanel extends Panel {

    private static final long serialVersionUID = 1L;
    private final Label activityContent;
    private final BookmarkablePageLink<Void> contentLink;
    private final Label timestampLabel;

    public NotificationPanel(String id, final ActivityMessage activity) {
        super(id);

        if (activity.getTask() != null)
            contentLink = new BookmarkablePageLink<Void>("contentLink", ViewTask.class, new PageParameters("id=" + activity.getTask().getTaskId()));
        else
            contentLink = new BookmarkablePageLink<Void>("contentLink", TeamFeedbackPage.class);
        contentLink.setOutputMarkupId(true);

        activityContent = new Label("activityContent", activity.getContent());
        activityContent.setOutputMarkupId(true);
        contentLink.add(activityContent);

        timestampLabel = new Label("timestamp", DateTimeUtils.toHumanFormat(activity.getTimestamp())) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onComponentTag(ComponentTag tag) {
                tag.setName("abbr");
                tag.getAttributes().put("title", DateTimeFormat.forPattern("EEEEE, d MMMMM yyyy 'at' HH:mm").print(activity.getTimestamp()));
            };
        };
        timestampLabel.setOutputMarkupId(true);

        contentLink.add(timestampLabel);
        add(contentLink);
    }

}
